/*
 * @lc app=leetcode id=27 lang=cpp
 *
 * [27] Remove Element
 */
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int len = nums.size();
        if (len < 1) {
            return 0;
        }

        int cnt = 0;
        int pos = 0;
        int last = -1;
        for (int i=0; i<len; i++) {
            if (val != nums[i]) {
                nums[pos++] = nums[i];
                cnt++;
            }
        }
        return cnt;
    }
};

